<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<!DOCTYPE HTML>
<html>
  <head> 
	<%@ include file="/platform/style.jsp"%>
	<style>
		
	</style>
	<script>
	function query(){
		$w.execForm({pageNum:1})
	}
	function add(){
		$w.openDialog({url:ctx+'/coupon/CouponPage@show.page',title:"添加优惠劵",w:700,h:450,maximized:true,afterClose:function(re){
			if(re){
				query();
			}
		}});
	}
	function edit(id){
		$w.openDialog({url:ctx+'/coupon/CouponPage@show.page?bean.id='+id,title:"编辑优惠劵",w:700,h:450,maximized:true,afterClose:function(re){
			if(re){
				query();
			}
		}});
	}
	function del(){
		window.parent.$w.confirmMsg("确定删除选中项？", function(r){
			if(r){
				$w.doUrl(ctx+"/coupon/CouponPage@del.page",$("#queryForm").serializeArray(),function(json){
					$w.execForm();
				})
			}
		})
	}
	function offshelf(){
		window.parent.$w.confirmMsg("确定下架选中项？", function(r){
			if(r){
				$w.doUrl(ctx+"/coupon/CouponPage@offshelf.page",$("#queryForm").serializeArray(),function(json){
					$w.execForm();
				})
			}
		})
	}
	
	function send(id){
		window.parent.$w.openDialog({url:ctx+'/user/UserPage@userselQuery.page',title:"选择客户",w:800,h:450,afterClose:function(re){
			if(re && re.length>0){
				var userids="";
				for(var i=0;i<re.length;i++){
					if(userids!="")userids+=",";
					userids+=re[i].id;
				}
				$w.doUrl(ctx+"/coupon/CouponPage@send.page?bean.id="+id+"&bean.userids="+userids,{},function(ret){
					if(ret.state=='ok'){
						window.parent.$w.correctMsg("派送成功!");
						$w.execForm();
					}
				})
			}
		}});
	}
	</script>
  </head>
  
  <body class="easyui-layout">
	<div data-options="region:'center'" class="bodybg">
		<!-- 查询区域 -->
		<form id="queryForm" action="/coupon/CouponPage.page" method="post">
		<w:hidden bind="pageNum"/>
		<w:hidden bind="pageSize_"/>
		<div class="easyui-panel ui-toolBar" border="false" data-options="doSize:false">
			<a href="javascript:;" class="easyui-linkbutton" plain="true" onclick="add()">添加优惠劵</a>
			<a href="javascript:;" class="easyui-linkbutton" plain="true" onclick="offshelf()" style="width:50px;">下架</a>
			<a href="javascript:;" class="easyui-linkbutton" plain="true" onclick="del()" style="width:50px;">删除</a>
		</div>
		<div class="ui_line" style="margin-top:10px"></div>
		<!-- 数据列表区域 -->
			<table class="ui-table" width="100%" cellpadding="1" cellspacing="1" data-options="showPage:true,
																								pageNum:<w:write bind="pageNum"/>,
																								pageSize:<w:write bind="pageSize_"/>,
																								total:<w:write bind="pagination.totalCount"/>,form:'queryForm'">
				<thead>
					<tr class="ui_th">
						<td width="30" align="center"><input type="checkbox" onclick="$selAllTbBoxs(this)"></td>
						<td width="30">ID</td>
						<td>面额</td>
						<td>最小订单金额</td>
						<td>开始日期</td>
						<td>结束日期</td>
						<td>数量</td>
						<td>已领取</td>
						<td>已使用</td>
						<td>状态</td>
						<td>优惠券说明</td>
						<td>使用范围</td>
						<td width="110" align="center">操作</td>
					</tr>
				</thead>
				<tbody>
				<w:iterate id="info" bind="resultList_">
					<tr class="ui_td">
						<td align="center"><input type="checkbox" name="primaryKey_" value="<w:write bind="#info.id"/>"></td>
						<td><w:write bind="#info.id"/></td>
						<td>￥<w:write bind="#info.offer_money"/></td>
						<td>￥<w:write bind="#info.min_money"/></td>
						<td><w:write bind="#info.startdate"/></td>
						<td><w:write bind="#info.enddate"/></td>
						<td><w:write bind="#info.amount"/></td>
						<td><w:write bind="#info.sales"/></td>
						<td><w:write bind="#info.usenum"/></td>
						<td><w:write bind="#info.state" format="[下架,上架]"/></td>
						<td><w:write bind="#info.explanation"/></td>
						<td><w:write bind="#info.source" defaultVal="通用" format="[通用,PC端,微信]"/></td>
						<td align="center">
							<a href="javascript:void(0);" class="ui_btn marginR8" onclick="edit(<w:write bind="#info.id"/>)">修改</a><a href="javascript:void(0);" class="ui_btn_2" onclick="send(<w:write bind="#info.id"/>)">发送</a>
						</td>
					</tr>
				</w:iterate>
				<w:switch><w:case bind="resultList_.size()==0"><tr class="ui_td"><td colspan="12">没有优惠劵信息！</td></tr></w:case></w:switch>
				</tbody>
			</table>
		</form>
	</div>
  </body>
</html>
